18 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21
22
#endif
23
24
#include <stdio.h>
25
26
/* local port to bind to */
27 #define LOCAL_PORT 1234
28
29
/* receive buffer length */
30 #define BUF_LEN 1024
31
32
int
33 main(void)
34 {
35 #ifdef WIN32
36 WSADATA wsa; /* used by WSAStartup() */
37 SOCKET sd = 0;
38 #else
39 int sd = 0;
40 #endif
41
42
struct sockaddr_in sin ;
43 char buf[BUF_LEN];
44 int ret = 0;
45
46
/* must initialize winsock if on win32 platform */
47 #ifdef WIN32
48 memset(&wsa, 0x0, sizeof(WSADATA));
49
50
if(WSAStartup(MAKEWORD(2, 0), &wsa) != 0x0)
51 {
52 printf("WSAStartup() failed.\n");
53 return(1);
54 }
55 #endif
56
57
/* create UDP socket */
58 sd = socket(AF_INET, SOCK_DGRAM, 0);
59 /* if Win32, check for INVALID_SOCKET constant */ ...