9 #include <sys/socket.h>
10 #include <netinet/in.h>
11 #include <netinet/tcp.h>
28 va_start( ap , format );
29 length = vsnprintf( NULL , 0 , format , ap );
33 output = (
char*)malloc(length+1);
34 vsnprintf( output , length+1 , format , ap );
37 while ((stop = strstr(output,
"\r\n"))) strcpy(stop, stop + 1);
39 send( sock , output , length , 0 );
40 send( sock ,
"\r\n" , 2 , 0 );
46 const int growsize = 80;
48 char* line = (
char*) malloc(growsize);
49 int len = growsize, pos = 0;
51 if (recv(sock, &c, 1, 0) <= 0)
break;
52 if (c ==
'\r')
continue;
57 line = (
char*) realloc(line, len);
71 struct sockaddr_in serv_addr;
78 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
79 perror(
"create socket");
83 if (connect(sock, (
struct sockaddr *)&serv_addr,
sizeof(serv_addr)) < 0) {
89 if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &on,
sizeof(on)) == -1) {
101 if (sock > 0) close(sock);
107 char *hostname = malloc (strlen (server) + 1);
108 if(hostname !=NULL) strcpy(hostname,server);
109 char *port = strchr( hostname,
':' );
110 struct hostent* host_ent;
115 default_port = atoi(port);
118 host_ent = gethostbyname(hostname);
119 if( host_ent == NULL )
121 perror(
"gethostbyname");
126 memset( sockaddr , 0 ,
sizeof(*sockaddr) );
127 sockaddr->sin_family = AF_INET;
128 memcpy( &sockaddr->sin_addr , host_ent->h_addr_list[0] , host_ent->h_length );
129 sockaddr->sin_port = htons(default_port);
137 struct sockaddr_in serv_addr;
145 sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
151 if( sendto(sock, (
char*)data , data_length , 0 , (
struct sockaddr*)&serv_addr ,
sizeof(serv_addr) ) > 0 )
int growl_tcp_parse_hostname(const char *const server, int default_port, struct sockaddr_in *const sockaddr)
void growl_tcp_write(int sock, const char *const format,...)
int growl_tcp_open(const char *server)
void growl_tcp_close(int sock)
char * growl_tcp_read(int sock)
#define closesocket(socket)
int growl_tcp_datagram(const char *server, const unsigned char *data, const int data_length)