Skip to content

Instantly share code, notes, and snippets.

@matteyeux
Last active November 25, 2016 08:33
Show Gist options
  • Save matteyeux/e49e362857f9bad898e2358baa981eb0 to your computer and use it in GitHub Desktop.
Save matteyeux/e49e362857f9bad898e2358baa981eb0 to your computer and use it in GitHub Desktop.
/*gcc get_netmask_suffix.c -o get_netmask_suffix*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
int main(int argc, char *argv[]){
int n, i=0;
// Il faut au moins un argument
if (argc != 2)
{
printf("usage : %s <netmask>\n", argv[0]);
return 0;
}
inet_pton(AF_INET, argv[1], &n);
while(n > 0){
n = n >> 1;
i++;
}
printf("Netmask suffix : %d\n", i);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment