Questions tagged [sockaddr-in]

29 questions
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…
talentless
  • 61
  • 5
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
  • 496
  • 6
  • 27
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
0
votes
1 answer

Unexpected compile error on specific sockaddr_in variable name

As part of a function that receives a struct ifreq *ifr argument, if I declare struct sockaddr_in name;, the program compiles, but if I name the variable struct sockaddr_in ifr_addr;, it fails with the following error: code.c:244:24: error: expected…
Bacon
  • 1,814
  • 3
  • 21
  • 36
0
votes
1 answer

Compare ipv4 address - sockaddr_in

I want to know if some address is in range 10.0.0.0 - 10.255.255.255. int localAddress = 0; struct sockaddr_in localOneFirst; struct sockaddr_in localOneLast; inet_pton(AF_INET, "11.0.0.0", &(address.sin_addr)); inet_pton(AF_INET, "10.0.0.0",…
JJ DD
  • 15
  • 3
0
votes
0 answers

C - Mavlink program : sendto fails and returns EINVAL while connecting to a drone

I'm trying to use a mavlink sample developed by Parrot to control a Bebop2 using mavlink protocol (link here). In order to send a message to the drone, they use the sendto function but I encounter an issue I cannot resolve : everytime I try to make…
0
votes
0 answers

Trying to get ipv4 from const sockaddr

BOOL f_WSAConnect(SOCKET s, const sockaddr *name, int namelen, LPWSABUF lpCallerData, LPWSABUF lpCalleeData, LPQOS lpSQOS, LPQOS lpGQOS) { MessageBoxA(NULL, name, "hi", MB_OK | MB_SYSTEMMODAL); return WSAConnect(NULL, NULL, NULL, NULL, NULL,…
0
votes
1 answer

What is the state of sockaddr on a failed accept()

The man pages don't cover the state of the sockaddr variable passed by reference into the accept() function in case of an error. Is it safe to assume that if something goes wrong between the time the client connects and the time you accept it,…
RobC
  • 502
  • 4
  • 17
0
votes
1 answer

Unable to copy ip address from string to sockaddr_in

I am trying to copy an IP address from a string to struct sockaddr_in but somehow there's some error popping up. #include #include #include #include #include int main(void) { …
re3el
  • 735
  • 2
  • 12
  • 28
0
votes
1 answer

Swift 3 - CFHostScheduleWithRunLoop crash

I am doing a reverse DNS in Swift, my previous code on Swift 2.2 was working fine, also I have implemented it in Objective-C and it works to. However I am not able to make it works in Swift 3.0 Swift 2.2 //: Let's set up the `sockaddr_in` C…
0
votes
1 answer

About passing ip to sockaddr_in struct

why is it that when we make a client progam, we pass the ip of the host we want to connect to like this: their_addr.sin_addr = *((struct in_addr *)he->h_addr); but this does not work: their_addr.sin_addr.s_addr = inet_addr("192.168.1.3"); but when…
Ioannis
  • 1
  • 1
0
votes
0 answers

c++ maps and struct sockaddr_in copying values and using sendto

okay, so I have a prob where when I try to get a struct sockaddr_in from my map, and use a tmp var to then send the stuct sockaddr_in through a socket using the method sendto. map userToAddrStrct; after I call recvfrom i…
poutyboi
  • 149
  • 5
  • 20
-1
votes
2 answers

Are there C functions to convert a sockaddr_in to a sockaddr_in6 structure?

I want to save data in a database using a canonicalized IP address. The software, at this point, may get IPv4 or IPv6 addresses. I want to canonicalize by converting all addresses to an IPv6 address. I know of inet_pton() to convert the string to a…
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
1
2