P
P
Pavel2016-03-27 20:48:33
linux
Pavel, 2016-03-27 20:48:33

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

2 answer(s)
S
Shetani, 2016-03-27
@Shetani

/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.

P
Pavel, 2016-03-27
@PavelG94

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 question

Ask a Question

731 491 924 answers to any question