Changeset 339


Ignore:
Timestamp:
Feb 20, 2009, 1:53:11 AM (9 years ago)
Author:
khorben
Message:

Added inet_addr() (untested)

Location:
trunk/System/Sources/libc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/System/Sources/libc/include/socket/arpa/inet.h

    r330 r339  
    1 /* $Id: inet.h,v 1.3 2009/02/19 21:08:08 khorben Exp $ */
     1/* $Id: inet.h,v 1.4 2009/02/20 00:35:17 khorben Exp $ */
    22/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
    33/* This file is part of DeforaOS System libc */
     
    2525uint32_t htonl(uint32_t host32);
    2626uint16_t htons(uint16_t host16);
     27in_addr_t inet_addr(const char *cp);
    2728uint32_t ntohl(uint32_t net32);
    2829uint16_t ntohs(uint16_t net16);
  • trunk/System/Sources/libc/src/socket/arpa/inet.c

    r330 r339  
    1 /* $Id: inet.c,v 1.2 2009/02/19 21:44:06 khorben Exp $ */
     1/* $Id: inet.c,v 1.3 2009/02/20 00:35:17 khorben Exp $ */
    22/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
    33/* This file is part of DeforaOS System libc */
     
    1717
    1818
     19#include "stdlib.h"
    1920#include "sys/types.h"
    2021#include "arpa/inet.h"
     
    4647
    4748
     49/* inet_addr */
     50in_addr_t inet_addr(const char *cp)
     51{
     52        in_addr_t ret = 0;
     53        unsigned long byte;
     54        char * p;
     55        int i;
     56
     57        if(cp == NULL || cp[0] == '\0')
     58                return -1;
     59        for(i = 0; i < 4; i++)
     60        {
     61                byte = strtoul(cp, &p, 0);
     62                if(*p != '.' && *p != '\0')
     63                        return -1;
     64                if(byte > 0xff)
     65                        return -1;
     66                ret = (ret << 8) | byte;
     67                if(*p == '\0')
     68                        return ret;
     69                cp = ++p;
     70        }
     71        return ret;
     72}
     73
     74
    4875/* ntohl */
    4976uint32_t ntohl(uint32_t net32)
Note: See TracChangeset for help on using the changeset viewer.