Commits

Thijs Alkemade  committed 9b615f5

Very bare bones registration implemented.

  • Participants

Comments (0)

Files changed (1)

+/* Sample UDP client */
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define GROWL_PROTOCOL_VERSION 1
+#define GROWL_UDP_PORT 9887
+#define GROWL_TYPE_REGISTRATION_NOAUTH 4
+#define GROWL_TYPE_NOTIFICATION_NOAUTH 5
+
+
+/*   while (fgets(sendline, 10000, stdin) != NULL)
+   {
+      sendto(sockfd,sendline,strlen(sendline),0,
+             (struct sockaddr *)&servaddr,sizeof(servaddr));
+      n=recvfrom(sockfd,recvline,10000,0,NULL,NULL);
+      recvline[n]=0;
+      fputs(recvline,stdout);
+   }*/
+
+int main(int argc, char**argv)
+{
+    int sockfd, n;
+    struct sockaddr_in servaddr, cliaddr;
+    char sendline[1000];
+    char recvline[1000];
+    
+    char *application = "cgrowl";
+    char *notification = "test";
+    
+    int index = 0;
+
+    if (argc != 2)
+    {
+        printf("usage:  %s <IP address>\n", argv[0]);
+        exit(1);
+    }
+
+    sockfd = socket(AF_INET,SOCK_DGRAM, 0);
+
+    bzero(&servaddr, sizeof(servaddr));
+    servaddr.sin_family = AF_INET;
+    servaddr.sin_addr.s_addr = inet_addr(argv[1]);
+    servaddr.sin_port = htons(GROWL_UDP_PORT);
+
+    sendline[index] = GROWL_PROTOCOL_VERSION; // ver
+    index++;
+    sendline[index] = GROWL_TYPE_REGISTRATION_NOAUTH; // type
+    index++;
+    index++;
+    sendline[index] = strlen(application); // app name length
+    index++;
+    
+    sendline[index] = 1; // ndef
+    index++;
+    sendline[index] = 1; // nall
+    index++;
+    
+    strcpy(sendline + index, application); // application name
+    index += strlen(application);
+    
+    index++;
+    sendline[index] = strlen(notification);
+    index++;
+    strcpy(sendline + index, notification);
+    index += strlen(notification);
+    sendline[index] = 1;  
+    index++;  
+    
+    int i;
+    for(i = 0; i < index; i ++) printf("%x (%c) ", sendline[i], sendline[i]);
+    printf("\n");
+    
+    sendto(sockfd, sendline, index, 0,
+           (struct sockaddr *)&servaddr, sizeof(servaddr));
+}