Answer the question
In order to leave comments, you need to log in
Why is the port number automatically overridden for a manually added entry in /etc/services?
Hello.
Added two entries to /etc/services: my-chat 5296/tcp and my-chat 5296/udp. When calling the getservbyname("my-chat", "tcp") function, the record is found, but its port is 45076. Tell me why this happens. Port number 5296 does not appear anywhere else in /etc/services.
Thank you.
Answer the question
In order to leave comments, you need to log in
/etc/services is not used to assign ports. Here is a description of why it is needed .
To run an application on a specific port, it must have an option like this -
eg.
Solved the problem. Everything works correctly, the getservbyname() function returns a structure in which the port number is written in network byte order. To get the value that is in the /etc/services file, you need to apply the ntohs () function to the port number in this structure.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question