Questions tagged [sockaddr-in]

27 questions
7
votes
1 answer

Why am I receiving 67 code from QOSStartTrackingClient method?

I am receiving error code 67 from the code below, which means ERROR_BAD_NET_NAME. Why is it happening? How can I fix it? SOCKADDR address; strcpy_s(address.sa_data, "8.8.8.8"); address.sa_family = AF_INET; if (!QOSStartTrackingClient(QoSHandle,…
Matin Lotfaliee
  • 1,512
  • 1
  • 18
  • 39
4
votes
2 answers

How to legally use type-punning with unions to cast between variations of struct sockaddr without violating the strict aliasing rule?

POSIX intends pointers to variations of struct sockaddr to be castable, however depending on the interpretation of the C standard this may be a violation of the strict aliasing rule and therefore UB. (See this answer with comments below it.) I can,…
user4385532
4
votes
1 answer

What does zero sockaddr_in mean in SCNetworkReachabilityCreateWithAddress?

tonymillion 's Reachability has +(Reachability *)reachabilityForInternetConnection { struct sockaddr_in zeroAddress; bzero(&zeroAddress, sizeof(zeroAddress)); zeroAddress.sin_len = sizeof(zeroAddress); zeroAddress.sin_family =…
onmyway133
  • 38,911
  • 23
  • 231
  • 237
3
votes
1 answer

C++ [UDP] How to keep track of all connected(clients) socket connections on server?

my server should forward the message it received to all connected clients but my code can only send the message back to the sender. struct User { char user_id[20]; string address; struct sockaddr_in CONNECTED; }U[8]; //USER LOGIN …
Lozy
  • 159
  • 4
  • 11
2
votes
2 answers

C sockaddr function call for sendto?

I'm currently setting up a UDP socket for a school assignment but I can't figure out how to properly send sockaddr as a parameter into a function. The input arguments for SendData is defined the same way they are in the sendto function. void…
Depe
  • 21
  • 2
2
votes
1 answer

Getting an IP address and port number from a sockaddr_in struct in Swift?

After much trial and error, and without any success, it seems I might need a bit of help on this one: How can I get IP address and port number from a sockaddr_in in the latest version of Swift? I saw some related questions but can't seem to find a…
2
votes
1 answer

sockaddr value changes unexpectedly after calling getaddrinfo()

I am programming an UDP client. I want to bind the socket to a given port on the client machine, so that the same port is always used for all sends. I get the sockaddr for the server using getaddrinfo, and I do the same to get the sockaddr which I…
joanlofe
  • 2,568
  • 1
  • 23
  • 40
1
vote
1 answer

how to provide custom IP to sockets in C?

How can I give a custom ip to my program, I've built a chat app, not the whatsapp, jus cui based simple chat app, coz imma beginner, I've used inet_addr() function, but it says can't assign ip, it only allows localhost IPs(127.0.0.1 to 127.0.0.254),…
BossySmaxx
  • 37
  • 6
1
vote
1 answer

getsockname returns -1, errno is EBADF?

The program runs up to the getsockname where the return is -1 and errno is 9 (EBADF, bad file descriptor). However, the code instrumented in Android app goes well. void sysLibCSendHookHandler(CPUState* env, int isStart){ if(isStart){ int fd =…
1
vote
2 answers

bind() - how to call bind() multiple times on the same socket

I use bind() on an address to which I have set port value equal to 0. I know that in this way, it is bind a random port to the address. But I want that only port with value x such that (x >= 0 && x <= 1023) || (x >= 49152) were choosen, but I…
user7836391
  • 31
  • 1
  • 4
1
vote
2 answers

sockaddr.sin_port = 1337 doesn't match the "real" opened port

I am trying to make a very simple server that accept a connection. int sock, serv; struct sockaddr_in in_sock; serv = socket(AF_INET, SOCK_STREAM, 0); in_sock.sin_addr.s_addr = 0; in_sock.sin_port = 1337; in_sock.sin_family = AF_INET; bind(serv,…
user96649
  • 371
  • 1
  • 3
  • 18
0
votes
1 answer

port number of an UDP socket

My OS is Ubuntu 20.x . I have two programs : server.c that listens to INADDR_ANY on the port 2052 and client.c that sends UDP packets locally on INADDR_LOOPBACK at the same port. The programs works fine and the received data and IP address match…
0
votes
0 answers

How do I set the Protocol field in an Ipv4 header to 41 in windows?

Background For my windows project I create RFC7217 ip global unicast addresses. Using Winsock2 and Microsoft's IpHelper functions these addresses get entered into the PC's local tables, then bind'ed to eventually become listening sockets. From…
rtischer8277
  • 410
  • 6
  • 23
0
votes
2 answers

Can't seem to save the client's address to sourceMsgs[j]

The title says it all, it might be a simple thing but I'm pretty much new at programming hence the stupid question.. I have: printf("sourcemsg: %s", inet_ntoa(sourceMsgs[j].sin_addr)); to see if the ip address that is saved in sourceMsgs[j] is the…
Jan Frank
  • 3
  • 2
0
votes
0 answers

why sockaddr_in and sockaddr each is imcompatible?

I try to memcpy ipv4 address in *ai(struct addrinfo) struct addrinfo *ai; char *p = (char *)(void *)(ai->ai_addr); memcpy(p + afd->a_off, "d83adcca", (size_t)afd->a_addrlen); // "d83adcca ipv4 address is hex data - not correct.." So, i need verify…
hyunsang park
  • 11
  • 1
  • 3
1
2