0

I am writing a simple FTP server program in C. I am mostly following Beej's Guide to Network Programming. In order to complete the pasv mode functionality, I have to create another socket and send its ip and port to the client.

Since gethostbyname() is deprecated, I am using getsockname() to get my current network IP address. My plan is that I separate two cases (ipv4 and ipv6) and send info to the client accordingly. But, whenever I try to get the address family it always 30. I am not sure if I am printing this correctly though.

I am doing something simple like this (which might include mistakes), and it prints 30.

struct sockaddr_storage my_addr;
int result;
socklen_t len = sizeof(my_addr);

result = getsockname(current_fd, (struct sockaddr *) &my_addr, &len);

if (my_addr.ss_family == AF_INET) { // ipv4
        struct sockaddr_in * ipv4 = (struct sockaddr_in *) &my_addr;
        addr = &(ipv4->sin_addr);
} else { // ipv6
        struct sockaddr_in6 * ipv6 = (struct sockaddr_in6 *) &my_addr;
        addr = &(ipv6->sin6_addr);
}

printf(" family: %u\n", (unsigned short) my_addr.ss_family);

When I searched this online, I got:

#define AF_ATM 30 /* ATM */

What is this exactly? Is this expected? If not, where am I doing something wrong?

Thank you.

Edit:

Apparently what it was printing was something different.

It is not defined as: #define AF_ATM 30 /* ATM */ but it is defines as: MT IPv6: Multi-Topology IP version 6 [RFC7307]

ege
  • 812
  • 6
  • 16
  • 1
    ATM is (was) a (completely forgotten by now) network protocol. It was superseded by IP family. More here: https://en.wikipedia.org/wiki/Asynchronous_transfer_mode – SergeyA Mar 28 '19 at 19:17
  • please post a [mcve] so we can reproduce the problem and help you debug it – user3629249 Mar 28 '19 at 19:41
  • @SergeyA I think you're a little premature with that obituary. – user207421 Mar 28 '19 at 23:49
  • `getsockname` has nothing to do with `gethostbyname`. `gethostbyname` is a library function to get (via DNS protocol) the DNS info of a host by its name. `getsockname` is a system call to get the local info of a socket. Nothing to do between them. – Luis Colorado Mar 30 '19 at 18:36
  • @user207421 do you know any wide application of ATM by now? – SergeyA Apr 01 '19 at 13:39

0 Answers0