Annotation of libaitio/src/tools.c, revision 1.16.4.1

1.2       misho       1: /*************************************************************************
1.4       misho       2: * (C) 2008 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org>
                      3: *  by Michael Pounov <misho@elwix.org>
1.2       misho       4: *
                      5: * $Author: misho $
1.16.4.1! misho       6: * $Id: tools.c,v 1.16 2012/07/22 20:39:45 misho Exp $
1.2       misho       7: *
1.4       misho       8: **************************************************************************
                      9: The ELWIX and AITNET software is distributed under the following
                     10: terms:
                     11: 
                     12: All of the documentation and software included in the ELWIX and AITNET
                     13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
                     14: 
1.9       misho      15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
1.4       misho      16:        by Michael Pounov <misho@elwix.org>.  All rights reserved.
                     17: 
                     18: Redistribution and use in source and binary forms, with or without
                     19: modification, are permitted provided that the following conditions
                     20: are met:
                     21: 1. Redistributions of source code must retain the above copyright
                     22:    notice, this list of conditions and the following disclaimer.
                     23: 2. Redistributions in binary form must reproduce the above copyright
                     24:    notice, this list of conditions and the following disclaimer in the
                     25:    documentation and/or other materials provided with the distribution.
                     26: 3. All advertising materials mentioning features or use of this software
                     27:    must display the following acknowledgement:
                     28: This product includes software developed by Michael Pounov <misho@elwix.org>
                     29: ELWIX - Embedded LightWeight unIX and its contributors.
                     30: 4. Neither the name of AITNET nor the names of its contributors
                     31:    may be used to endorse or promote products derived from this software
                     32:    without specific prior written permission.
                     33: 
                     34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
                     35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     44: SUCH DAMAGE.
                     45: */
1.2       misho      46: #include "global.h"
                     47: #include "aitio.h"
                     48: 
                     49: 
                     50: /*
1.11      misho      51:  * io_LTrimStr() - Remove left whitespaces from text string
1.10      misho      52:  *
1.2       misho      53:  * @psLine = Text string
                     54:  * return: 0 nothing to do; !=0 Removed bytes
                     55: */
1.5       misho      56: inline int
1.11      misho      57: io_LTrimStr(char * __restrict psLine)
1.2       misho      58: {
                     59:        int pos = 0;
1.11      misho      60:        char *s;
1.2       misho      61: 
                     62:        if (!psLine || !*psLine)
                     63:                return 0;
                     64: 
1.11      misho      65:        for (s = psLine; isspace((u_char) *s); s++);
1.2       misho      66:        pos = s - psLine;
                     67: 
1.11      misho      68:        memmove(psLine, s, (strlen(psLine) - pos) + 1);
1.2       misho      69:        return pos;
                     70: }
                     71: 
                     72: /*
1.11      misho      73:  * io_RTrimStr() - Remove right whitespaces from text string
1.10      misho      74:  *
1.2       misho      75:  * @psLine = Text string
                     76:  * return: 0 nothing to do; !=0 Removed bytes
                     77: */
1.5       misho      78: inline int
1.11      misho      79: io_RTrimStr(char * __restrict psLine)
1.2       misho      80: {
1.11      misho      81:        char *t, *pos;
1.2       misho      82: 
                     83:        if (!psLine || !*psLine)
                     84:                return 0;
                     85: 
1.11      misho      86:        pos = psLine + strlen(psLine);
                     87:        for (t = pos - 1; t > psLine && isspace((u_char) *t); t--);
1.2       misho      88:        *++t = 0;
                     89: 
                     90:        return pos - t;
                     91: }
                     92: 
                     93: /*
1.11      misho      94:  * io_TrimStr() - Remove left and right whitespaces from text string
1.10      misho      95:  *
1.2       misho      96:  * @psLine = Text string
                     97:  * return: 0 nothing to do; !=0 Removed bytes
                     98: */
1.5       misho      99: inline int
1.11      misho     100: io_TrimStr(char * __restrict psLine)
1.2       misho     101: {
                    102:        int ret = 0;
                    103: 
                    104:        ret = io_LTrimStr(psLine);
                    105:        ret += io_RTrimStr(psLine);
                    106: 
                    107:        return ret;
                    108: }
                    109: 
                    110: /*
1.11      misho     111:  * io_UnquotStr() - Remove quots from input text string 
1.10      misho     112:  *
1.2       misho     113:  * @psLine = Text string
                    114:  * return: 0 nothing to do; 1 successful unquoted string
                    115: */
1.5       misho     116: inline int
1.11      misho     117: io_UnquotStr(char * __restrict psLine)
1.2       misho     118: {
                    119:        char *pos, *str = NULL;
                    120:        int flg;
                    121: 
                    122:        if (!psLine)
                    123:                return 0;
                    124: 
1.11      misho     125:        if (*psLine == '"' || *psLine == '\'') {
1.15      misho     126:                str = io_strdup(psLine + 1);
1.11      misho     127:                for (pos = str, flg = 0; *pos; flg = ('\\' == *pos), pos++) {
                    128:                        if (!flg && *pos == *psLine) {
                    129:                                *pos = 0;
                    130:                                strlcpy(psLine, str, strlen(psLine) + 1);
                    131:                                break;
1.2       misho     132:                        }
1.11      misho     133:                }
1.15      misho     134:                io_free(str);
1.11      misho     135:                return 1;
1.2       misho     136:        }
                    137: 
                    138:        return 0;
                    139: }
                    140: 
                    141: /*
1.11      misho     142:  * io_Ch2Hex() - Convert from Char string to Hex string
1.10      misho     143:  *
1.2       misho     144:  * @psLine = Text string
                    145:  * @lineLen = Length of Text string
1.15      misho     146:  * return: NULL nothing to do or error; !=0 Allocated new converted data without term\0 (must be io_free)
1.2       misho     147: */
1.5       misho     148: inline u_char *
                    149: io_Ch2Hex(u_char *psLine, int lineLen)
1.2       misho     150: {
                    151:        register int i;
1.3       misho     152:        char szWork[3];
                    153:        u_char *str;
1.2       misho     154: 
                    155:        if (!psLine || !*psLine || !lineLen)
                    156:                return NULL;
                    157: 
1.15      misho     158:        str = io_malloc(lineLen / 2);
1.2       misho     159:        if (!str) {
                    160:                LOGERR;
                    161:                return NULL;
                    162:        } else
1.3       misho     163:                memset(str, 0, lineLen / 2);
1.2       misho     164: 
1.3       misho     165:        for (i = 0; i < lineLen && psLine[i * 2]; i++) {
                    166:                strlcpy(szWork, (char*) &psLine[i * 2], 3);
                    167:                str[i] = (u_char) strtol(szWork, NULL, 16);
1.2       misho     168:        }
                    169: 
                    170:        return str;
                    171: }
                    172: 
                    173: 
                    174: /*
1.11      misho     175:  * io_Hex2Ch() - Convert from Hex string to Char string
1.10      misho     176:  *
1.2       misho     177:  * @psLine = Text string
                    178:  * @lineLen = Length of Text string
1.15      misho     179:  * return: NULL nothing to do or error; !=0 Allocated new converted string(must be io_free)
1.2       misho     180: */
1.5       misho     181: inline char *
                    182: io_Hex2Ch(u_char *psLine, int lineLen)
1.2       misho     183: {
                    184:        register int i;
                    185:        char szWork[3], *str;
                    186: 
                    187:        if (!psLine || !*psLine || !lineLen)
                    188:                return NULL;
                    189: 
1.15      misho     190:        str = io_malloc(lineLen * 2 + 1);
1.2       misho     191:        if (!str) {
                    192:                LOGERR;
                    193:                return NULL;
                    194:        } else
1.3       misho     195:                memset(str, 0, lineLen * 2 + 1);
1.2       misho     196: 
1.3       misho     197:        for (i = 0; i <= lineLen; i++) {
                    198:                memset(szWork, 0, 3);
                    199:                snprintf(szWork, 3, "%02X", (u_char) psLine[i]);
                    200:                strncat(str, szWork, 2);
1.2       misho     201:        }
                    202: 
                    203:        return str;
                    204: }
1.5       misho     205: 
                    206: /*
1.11      misho     207:  * io_CopyEnv() - Copy environment to new environment array;
1.10      misho     208:  *
1.5       misho     209:  * @oldenv = Environment array
1.15      misho     210:  * return: NULL error; !=NULL Allocated new environment array(must be io_free)
1.5       misho     211: */
                    212: char **
                    213: io_CopyEnv(const char **oldenv)
                    214: {
                    215:        char **newenv, **el;
                    216:        register int i, num;
                    217: 
                    218:        if (!oldenv)
                    219:                return NULL;
                    220:        else
                    221:                newenv = el = NULL;
                    222: 
                    223:        /* count items environment */
                    224:        for (i = num = 0; oldenv[i]; i++)
                    225:                if (*strchr(oldenv[i], '='))
                    226:                        num++;
                    227: 
                    228:        /* create and copy new environment */
1.15      misho     229:        newenv = io_calloc(num + 1, sizeof(char*));
1.5       misho     230:        if (!newenv) {
                    231:                LOGERR;
                    232:                return NULL;
                    233:        } else
                    234:                el = newenv;
                    235: 
                    236:        for (i = 0; oldenv[i]; i++)
                    237:                if (*strchr(oldenv[i], '=')) {
1.15      misho     238:                        *el = io_strdup(oldenv[i]);
1.5       misho     239:                        el++;
                    240:                }
                    241:        *el = NULL;
                    242: 
                    243:        return newenv;
                    244: }
                    245: 
                    246: /*
1.11      misho     247:  * io_ExecArgs() - Build exec arguments from other array
1.10      misho     248:  *
1.5       misho     249:  * @psProg = Program name for execute
                    250:  * @oldarg = Arguments array
1.15      misho     251:  * return: NULL error; !=NULL Allocated execution array(must be io_free)
1.5       misho     252: */
                    253: char **
                    254: io_ExecArgs(const char *psProg, const char **oldarg)
                    255: {
                    256:        char **newarg, **el;
                    257:        register int i, num;
                    258: 
                    259:        if (!psProg || !oldarg)
                    260:                return NULL;
                    261:        else
                    262:                newarg = el = NULL;
                    263: 
                    264:        /* count items arguments */
                    265:        for (num = 0; oldarg[num]; num++);
                    266: 
                    267:        /* create and copy new arguments */
1.15      misho     268:        newarg = io_calloc(num + 2, sizeof(char*));
1.5       misho     269:        if (!newarg) {
                    270:                LOGERR;
                    271:                return NULL;
                    272:        } else
                    273:                el = newarg;
                    274: 
1.15      misho     275:        *el = io_strdup(psProg);
1.5       misho     276:        el++;
                    277: 
                    278:        for (i = 0; oldarg[i]; i++, el++)
1.15      misho     279:                *el = io_strdup(oldarg[i]);
1.5       misho     280:        *el = NULL;
                    281: 
                    282:        return newarg;
                    283: }
                    284: 
                    285: /*
1.11      misho     286:  * io_FreeNullTerm() - Free dynamic allocated null terminated array with strings
1.10      misho     287:  *
1.5       misho     288:  * @arr = Pointer to array for free
                    289:  * return: none
                    290: */
                    291: inline void
                    292: io_FreeNullTerm(char *** __restrict arr)
                    293: {
                    294:        char **a;
                    295: 
                    296:        if (arr && *arr) {
                    297:                a = *arr;
                    298:                while (a && *a)
1.15      misho     299:                        io_free(*a++);
                    300:                io_free(*arr);
1.5       misho     301:                *arr = NULL;
                    302:        }
                    303: }
1.6       misho     304: 
                    305: /*
1.16.4.1! misho     306:  * io_MakeAV() Parse and make attribute/value pair
        !           307:  *
        !           308:  * @csArgs = Input argument line
        !           309:  * @csDelim = Delimiter for separate
        !           310:  * @psAttr = Output Attribute
        !           311:  * @attrLen = Size of attribute array
        !           312:  * @psValue = Output Value, if ==NULL this element not present value or not wanted for return
        !           313:  * @valLen = Size of value array
        !           314:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
        !           315: */
        !           316: int
        !           317: io_MakeAV(const char * __restrict csArgs, const char *csDelim, 
        !           318:                char * __restrict psAttr, int attrLen, char * __restrict psValue, int valLen)
        !           319: {
        !           320:        register int ret = 0;
        !           321:        char *pos, *psBuf;
        !           322: 
        !           323:        if (!csArgs || !csDelim || !psAttr || !attrLen)
        !           324:                return -1;
        !           325:        if (psValue && !valLen)
        !           326:                return -1;
        !           327:        else
        !           328:                memset(psValue, 0, valLen);
        !           329:        psBuf = io_strdup(csArgs);
        !           330:        if (!psBuf) {
        !           331:                LOGERR;
        !           332:                return -1;
        !           333:        }
        !           334: 
        !           335:        pos = strpbrk(psBuf, csDelim);
        !           336:        if (pos)
        !           337:                *pos++ = 0;
        !           338:        ret++;
        !           339:        strlcpy(psAttr, psBuf, attrLen);
        !           340: 
        !           341:        if (pos && *pos) {
        !           342:                ret++;
        !           343:                if (psValue)
        !           344:                        strlcpy(psValue, pos, valLen);
        !           345:        }
        !           346: 
        !           347:        io_free(psBuf);
        !           348:        return ret;
        !           349: }
        !           350: 
        !           351: /*
        !           352:  * io_MakeAV2() Parse and make attribute/value pair over input string
        !           353:  *
        !           354:  * @csArgs = Input argument line, will be modified!
        !           355:  * @csDelim = Delimiter for separate
        !           356:  * @psAttr = Output Attribute
        !           357:  * @psValue = Output Value, if ==NULL this element not present value or not wanted for return
        !           358:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
        !           359: */
        !           360: int
        !           361: io_MakeAV2(char * __restrict psArgs, const char *csDelim, 
        !           362:                char ** __restrict psAttr, char ** __restrict psValue)
        !           363: {
        !           364:        register int ret = 0;
        !           365:        char *pos;
        !           366: 
        !           367:        if (!psArgs || !csDelim)
        !           368:                return -1;
        !           369: 
        !           370:        pos = strpbrk(psArgs, csDelim);
        !           371:        if (pos) {
        !           372:                *pos++ = 0;
        !           373:                ret++;
        !           374:                if (psAttr)
        !           375:                        *psAttr = psArgs;
        !           376:        } else
        !           377:                return 0;
        !           378: 
        !           379:        if (psValue) {
        !           380:                if (pos && *pos) {
        !           381:                        ret++;
        !           382:                        *psValue = pos;
        !           383:                } else
        !           384:                        *psValue = NULL;
        !           385:        }
        !           386: 
        !           387:        return ret;
        !           388: }
        !           389: 
        !           390: /*
1.9       misho     391:  * io_Path2File() - Parse and make path/filename pair
                    392:  *
                    393:  * @csArgs = Input argument line
                    394:  * @psPath = Output Path, if ==NULL path not returned
                    395:  * @pathLen = Size of path array
                    396:  * @psFile = Output File
                    397:  * @fileLen = Size of file array
                    398:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
                    399:  */
                    400: inline int
                    401: io_Path2File(const char * __restrict csArgs, char * __restrict psPath, 
                    402:                int pathLen, char * __restrict psFile, int fileLen)
                    403: {
                    404:        char *pos, *psBuf;
                    405: 
                    406:        if (!csArgs || !psFile || !fileLen)
                    407:                return -1;
                    408:        if (psPath && !pathLen)
                    409:                return -1;
                    410: 
1.15      misho     411:        psBuf = io_strdup(csArgs);
1.9       misho     412:        if (!psBuf) {
                    413:                LOGERR;
                    414:                return -1;
                    415:        }
                    416: 
                    417:        pos = strrchr(psBuf, '/');
                    418:        if (!pos) {
                    419:                strlcpy(psFile, psBuf, fileLen);
                    420: 
1.15      misho     421:                io_free(psBuf);
1.9       misho     422:                return 1;
                    423:        } else
                    424:                *pos++ = 0;
                    425: 
                    426:        strlcpy(psFile, pos, fileLen);
                    427:        if (psPath)
                    428:                strlcpy(psPath, psBuf, pathLen);
                    429: 
1.15      misho     430:        io_free(psBuf);
1.9       misho     431:        return 2;
                    432: }
                    433: 
                    434: /*
1.11      misho     435:  * io_ether_ntoa() - Convert ethernet address to string
1.10      misho     436:  *
1.6       misho     437:  * @n = ethernet address structure, like struct ether_addr
                    438:  * @a = string
                    439:  * @len = string length
                    440:  * return: NULL error or !=NULL string a
                    441:  */
                    442: inline char *
                    443: io_ether_ntoa(const struct io_ether_addr *n, char * __restrict a, int len)
                    444: {
                    445:        if (!n || !a)
                    446:                return NULL;
                    447: 
                    448:        memset(a, 0, len);
                    449:        if (snprintf(a, len, "%02x:%02x:%02x:%02x:%02x:%02x", 
                    450:                        n->ether_addr_octet[0], n->ether_addr_octet[1], 
                    451:                        n->ether_addr_octet[2], n->ether_addr_octet[3], 
                    452:                        n->ether_addr_octet[4], n->ether_addr_octet[5]) < 17)
                    453:                return NULL;
                    454: 
                    455:        return a;
                    456: }
                    457: 
                    458: /*
1.11      misho     459:  * io_ether_aton() - Convert string to ethernet address
1.10      misho     460:  *
1.6       misho     461:  * @a = string
                    462:  * @e = ethernet address structure, like struct ether_addr
                    463:  * return: NULL error or !=NULL ethernet address structure
                    464:  */
                    465: inline struct io_ether_addr *
                    466: io_ether_aton(const char *a, struct io_ether_addr *e)
                    467: {                       
                    468:        int i;
                    469:        u_int o0, o1, o2, o3, o4, o5;
                    470: 
                    471:        if (!a || !e)
                    472:                return NULL;
                    473: 
                    474:        i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o0, &o1, &o2, &o3, &o4, &o5);
                    475:        if (i != 6)
                    476:                return NULL;
                    477: 
                    478:        e->ether_addr_octet[0] = o0;
                    479:        e->ether_addr_octet[1] = o1;
                    480:        e->ether_addr_octet[2] = o2;
                    481:        e->ether_addr_octet[3] = o3;
                    482:        e->ether_addr_octet[4] = o4;
                    483:        e->ether_addr_octet[5] = o5;
                    484: 
                    485:        return e;
                    486: }
1.7       misho     487: 
                    488: /*
1.11      misho     489:  * io_n2port() - Extract port from network structure
1.10      misho     490:  *
1.7       misho     491:  * @addr = Address
                    492:  * return: 0 not supported family type or port number
                    493:  */
                    494: inline u_short
                    495: io_n2port(io_sockaddr_t * __restrict addr)
                    496: {
                    497:        u_short port = 0;
                    498: 
                    499:        if (!addr)
                    500:                return port;
                    501: 
                    502:        switch (addr->sa.sa_family) {
                    503:                case AF_INET:
                    504:                        return ntohs(addr->sin.sin_port);
                    505:                case AF_INET6:
                    506:                        return ntohs(addr->sin6.sin6_port);
                    507:                default:
                    508:                        break;
                    509:        }
                    510: 
                    511:        return port;
                    512: }
                    513: 
                    514: /*
1.11      misho     515:  * io_n2addr() - Extract address from network structure
1.10      misho     516:  *
1.7       misho     517:  * @addr = Address
                    518:  * @val = Value for store string address
                    519:  * return: NULL error or !=NULL string address from val
                    520:  */
                    521: const char *
                    522: io_n2addr(io_sockaddr_t * __restrict addr, ait_val_t * __restrict val)
                    523: {
                    524:        char str[INET6_ADDRSTRLEN] = { 0 };
                    525:        const char *ret = NULL;
                    526: 
                    527:        if (!addr || !val)
                    528:                return ret;
                    529: 
1.13      misho     530:        AIT_INIT_VAL(val);
1.7       misho     531:        switch (addr->sa.sa_family) {
                    532:                case AF_INET:
                    533:                        if (!inet_ntop(AF_INET, &addr->sin.sin_addr, str, INET_ADDRSTRLEN)) {
                    534:                                LOGERR;
                    535:                                return ret;
                    536:                        } else
                    537:                                ret = str;
                    538:                        break;
                    539:                case AF_INET6:
                    540:                        if (!inet_ntop(AF_INET6, &addr->sin6.sin6_addr, str, INET6_ADDRSTRLEN)) {
                    541:                                LOGERR;
                    542:                                return ret;
                    543:                        } else
                    544:                                ret = str;
                    545:                        break;
1.13      misho     546:                case AF_LOCAL:
                    547:                        ret = addr->sun.sun_path;
                    548:                        break;
1.7       misho     549:                default:
                    550:                        io_SetErr(EPROTONOSUPPORT, "Unsuported address family %d", 
                    551:                                        addr->sa.sa_family);
                    552:                        return ret;
                    553:        }
                    554: 
                    555:        AIT_SET_STR(val, ret);
1.8       misho     556:        return (const char*) AIT_GET_STR(val);
1.7       misho     557: }
                    558: 
                    559: /*
1.11      misho     560:  * io_gethostbyname() - Get host and port and make network structure
1.10      misho     561:  *
1.7       misho     562:  * @psHost = Hostname
                    563:  * @port = Port
                    564:  * @addr = Network address structure
                    565:  * return: NULL error or !=NULL network structure
                    566:  */
                    567: io_sockaddr_t *
                    568: io_gethostbyname(const char *psHost, u_short port, io_sockaddr_t * __restrict addr)
                    569: {
1.12      misho     570:        struct hostent *host = NULL;
1.7       misho     571: 
                    572:        if (!psHost || !addr)
                    573:                return NULL;
                    574: 
1.12      misho     575:        if (*psHost != '/') {
                    576:                /* resolver */
                    577:                if (!addr->sa.sa_family)
                    578:                        host = gethostbyname(psHost);
                    579:                else
                    580:                        host = gethostbyname2(psHost, addr->sa.sa_family);
                    581:                if (!host) {
                    582:                        io_SetErr(EINVAL, "Resolver #%d - %s", h_errno, hstrerror(h_errno));
                    583:                        return NULL;
1.16      misho     584:                } else {
                    585:                        memset(addr, 0, sizeof(io_sockaddr_t));
1.12      misho     586:                        addr->sa.sa_family = host->h_addrtype;
1.16      misho     587:                }
                    588:        } else {
                    589:                memset(addr, 0, sizeof(io_sockaddr_t));
1.12      misho     590:                addr->sa.sa_family = AF_LOCAL;
1.16      misho     591:        }
                    592:                
1.7       misho     593: 
1.12      misho     594:        switch (addr->sa.sa_family) {
1.7       misho     595:                case AF_INET:
                    596:                        addr->sin.sin_len = sizeof(struct sockaddr_in);
                    597:                        addr->sin.sin_family = AF_INET;
                    598:                        addr->sin.sin_port = htons(port);
                    599:                        memcpy(&addr->sin.sin_addr, host->h_addr, sizeof addr->sin.sin_addr);
                    600:                        return addr;
                    601:                case AF_INET6:
                    602:                        addr->sin6.sin6_len = sizeof(struct sockaddr_in6);
                    603:                        addr->sin6.sin6_family = AF_INET6;
                    604:                        addr->sin6.sin6_port = htons(port);
                    605:                        memcpy(&addr->sin6.sin6_addr, host->h_addr, sizeof addr->sin6.sin6_addr);
                    606:                        return addr;
1.12      misho     607:                case AF_LOCAL:
                    608:                        addr->sun.sun_len = sizeof(struct sockaddr_un);
                    609:                        addr->sun.sun_family = AF_LOCAL;
                    610:                        memset(addr->sun.sun_path, 0, sizeof addr->sun.sun_path);
                    611:                        snprintf(addr->sun.sun_path, sizeof addr->sun.sun_path, "%s-%hu", psHost, port);
                    612:                        return addr;
1.7       misho     613:                default:
1.12      misho     614:                        io_SetErr(EPROTONOSUPPORT, "Unsuported address family %d", addr->sa.sa_family);
1.7       misho     615:                        break;
                    616:        }
                    617: 
                    618:        return NULL;
                    619: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>