I am trying to learn about socket programming, and I have the following function to set up a socket:
29 int CreatePassiveSock(char *protocol, char *portstr, int qlen) {
30 int s, port, type, saddrlen;
31 char *endptr;
32 struct sockaddr_in saddr;
33 port = (int) strtol(portstr, &endptr, 10);
34 if (*endptr) {
35 printf("\nPlease specify a positive integer for port\n");
36 exit(1);
37 }
38 saddrlen = sizeof(saddr);
39 memset(&saddr, 0, saddrlen);
40 saddr.sin_family = AF_INET;
41 saddr.sin_addr.s_addr = INADDR_ANY;
42 saddr.sin_port = htons(port);
43 if (strcmp("tcp", protocol) == 0)
44 type = SOCK_STREAM;
45 else if (strcmp("udp", protocol) == 0)
46 type = SOCK_DGRAM;
47 else {
48 printf("Unsupported protocol given");
49 exit(1);
50 }
51 if ((s = socket(PF_INET, type, 0)) == -1){
52 perror("socket call failed");
53 exit(1);
54 }
55 if (bind(s, (struct sockaddr *)&saddr, saddrlen) == -1) {
56 perror("Bind failed");
57 exit(1);
58 }
59 if (type == SOCK_STREAM) {
60 if (listen(s, qlen) == -1) {
61 perror("listen failed");
62 exit(1);
63 }
64 }
65 return s;
66 }
When I call this with 6001 as port number, this is the line that shows up with netstat -a | head
tcp 0 0 0.0.0.0:x11-1 0.0.0.0:* LISTEN
Why would it show up as 0.0.0.0:x11-1? Shouldn't I get 0.0.0.0:6001?
If it matters I am doing this on a laptop running PopOS.