]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
Make example code more complete.
authorMichael Kerrisk <mtk.manpages@gmail.com>
Wed, 5 Jul 2006 14:40:00 +0000 (14:40 +0000)
committerMichael Kerrisk <mtk.manpages@gmail.com>
Wed, 5 Jul 2006 14:40:00 +0000 (14:40 +0000)
man2/bind.2

index 57e2e9268a511d4044cc2cd35a1a6c1137bbc78e..6fd92e0493f84fc7b52badb8a1e21ca5efbe73c1 100644 (file)
@@ -154,23 +154,33 @@ domain:
 .nf
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <stdlib.h>
+#include <stdlio.h>
 
-int sfd;
-struct sockaddr_un addr;
+int
+main(int argc, char *argv[])
+{
+    int sfd;
+    struct sockaddr_un addr;
+    
+    sfd = socket(AF_UNIX, SOCK_STREAM, 0);         
+    if (sfd == -1) { 
+        perror("socket"); 
+        exit(EXIT_FAILURE); 
+    }
 
-sfd = socket(AF_UNIX, SOCK_STREAM, 0);         
-if (sfd == -1) { perror("socket"); exit(EXIT_FAILURE); }
-
-memset(&addr, 0, sizeof(struct sockaddr_un));  
+    memset(&addr, 0, sizeof(struct sockaddr_un));  
                         /* Clear structure */
-addr.sun_family = AF_UNIX;                     
-strncpy(addr.sun_path, MY_SOCK_PATH, 
-        sizeof(addr.sun_path) - 1);
+    addr.sun_family = AF_UNIX;                     
+    strncpy(addr.sun_path, MY_SOCK_PATH, 
+            sizeof(addr.sun_path) - 1);
 
-if (bind(sfd, (struct sockaddr *) &addr,
-        sizeof(struct sockaddr_un)) == -1) { 
-    perror("bind"); 
-    exit(EXIT_FAILURE); 
+    if (bind(sfd, (struct sockaddr *) &addr,
+            sizeof(struct sockaddr_un)) == -1) { 
+        perror("bind"); 
+        exit(EXIT_FAILURE); 
+    }
+    ...
 }
 .fi
 .in -0.25in