\doxysection{sockaddr\+\_\+str.\+h}
\label{sockaddr__str_8h_source}\index{include/osmocom/core/sockaddr\_str.h@{include/osmocom/core/sockaddr\_str.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 }
\DoxyCodeLine{4 \textcolor{comment}{/*}}
\DoxyCodeLine{5 \textcolor{comment}{ * (C) 2019 by sysmocom -\/ s.f.m.c. GmbH <info@sysmocom.de>}}
\DoxyCodeLine{6 \textcolor{comment}{ *}}
\DoxyCodeLine{7 \textcolor{comment}{ * Author: neels@hofmeyr.de}}
\DoxyCodeLine{8 \textcolor{comment}{ *}}
\DoxyCodeLine{9 \textcolor{comment}{ * All Rights Reserved}}
\DoxyCodeLine{10 \textcolor{comment}{ *}}
\DoxyCodeLine{11 \textcolor{comment}{ * SPDX-\/License-\/Identifier: GPL-\/2.0+}}
\DoxyCodeLine{12 \textcolor{comment}{ *}}
\DoxyCodeLine{13 \textcolor{comment}{ * This program is free software; you can redistribute it and/or modify}}
\DoxyCodeLine{14 \textcolor{comment}{ * it under the terms of the GNU General Public License as published by}}
\DoxyCodeLine{15 \textcolor{comment}{ * the Free Software Foundation; either version 2 of the License, or}}
\DoxyCodeLine{16 \textcolor{comment}{ * (at your option) any later version.}}
\DoxyCodeLine{17 \textcolor{comment}{ *}}
\DoxyCodeLine{18 \textcolor{comment}{ * This program is distributed in the hope that it will be useful,}}
\DoxyCodeLine{19 \textcolor{comment}{ * but WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{20 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the}}
\DoxyCodeLine{21 \textcolor{comment}{ * GNU General Public License for more details.}}
\DoxyCodeLine{22 \textcolor{comment}{ *}}
\DoxyCodeLine{23 \textcolor{comment}{ */}}
\DoxyCodeLine{24 }
\DoxyCodeLine{25 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{26 }
\DoxyCodeLine{27 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{28 \textcolor{preprocessor}{\#include <stdbool.h>}}
\DoxyCodeLine{29 \textcolor{preprocessor}{\#include <arpa/inet.h>}}
\DoxyCodeLine{30 \textcolor{preprocessor}{\#include <osmocom/core/defs.h>}}
\DoxyCodeLine{31 }
\DoxyCodeLine{32 \textcolor{keyword}{struct }in\_addr;}
\DoxyCodeLine{33 \textcolor{keyword}{struct }in6\_addr;}
\DoxyCodeLine{34 \textcolor{keyword}{struct }sockaddr\_storage;}
\DoxyCodeLine{35 \textcolor{keyword}{struct }sockaddr\_in;}
\DoxyCodeLine{36 \textcolor{keyword}{struct }sockaddr\_in6;}
\DoxyCodeLine{37 \textcolor{keyword}{struct }osmo\_sockaddr;}
\DoxyCodeLine{38 }
\DoxyCodeLine{44 \textcolor{keywordtype}{int} osmo\_ip\_str\_type(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *ip);}
\DoxyCodeLine{45 }
\DoxyCodeLine{46 \textcolor{keyword}{struct }osmo\_sockaddr\_str \{}
\DoxyCodeLine{48         \textcolor{keywordtype}{int} af;}
\DoxyCodeLine{50         \textcolor{keywordtype}{char} ip[INET6\_ADDRSTRLEN];}
\DoxyCodeLine{52         uint16\_t port;}
\DoxyCodeLine{53 \};}
\DoxyCodeLine{54 }
\DoxyCodeLine{62 \textcolor{preprocessor}{\#define OSMO\_SOCKADDR\_STR\_FMT "{}\%s\%s\%s:\%u"{}}}
\DoxyCodeLine{63 \textcolor{preprocessor}{\#define OSMO\_SOCKADDR\_STR\_FMT\_ARGS\_NOT\_NULL(R) \(\backslash\)}}
\DoxyCodeLine{64 \textcolor{preprocessor}{        ((R)-\/>af == AF\_INET6) ? "{}["{}} : "{}"{}, \(\backslash\)}
\DoxyCodeLine{65         (R)-\/>ip, \(\backslash\)}
\DoxyCodeLine{66         ((R)-\/>af == AF\_INET6) ? "{}]"{} : "{}"{}, \(\backslash\)}
\DoxyCodeLine{67         (R)-\/>port}
\DoxyCodeLine{68 \textcolor{preprocessor}{\#define OSMO\_SOCKADDR\_STR\_FMT\_ARGS(R) \(\backslash\)}}
\DoxyCodeLine{69 \textcolor{preprocessor}{        ((R) \&\& (R)-\/>af == AF\_INET6) ? "{}["{}} : "{}"{}, \(\backslash\)}
\DoxyCodeLine{70         (R) ? (R)-\/>ip : "{}NULL"{}, \(\backslash\)}
\DoxyCodeLine{71         ((R) \&\& (R)-\/>af == AF\_INET6) ? "{}]"{} : "{}"{}, \(\backslash\)}
\DoxyCodeLine{72         (R) ? (R)-\/>port : 0}
\DoxyCodeLine{73 }
\DoxyCodeLine{74 \textcolor{keywordtype}{bool} osmo\_sockaddr\_str\_is\_set(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str);}
\DoxyCodeLine{75 \textcolor{keywordtype}{bool} osmo\_sockaddr\_str\_is\_nonzero(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str);}
\DoxyCodeLine{76 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_cmp(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *a, \textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *b);}
\DoxyCodeLine{77 }
\DoxyCodeLine{78 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_from\_str(\textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *ip, uint16\_t port);}
\DoxyCodeLine{79 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_from\_str2(\textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *ip);}
\DoxyCodeLine{80 }
\DoxyCodeLine{81 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_from\_in\_addr(\textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{const} \textcolor{keyword}{struct} in\_addr *addr, uint16\_t port);}
\DoxyCodeLine{82 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_from\_in6\_addr(\textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{const} \textcolor{keyword}{struct} in6\_addr *addr, uint16\_t port);}
\DoxyCodeLine{83 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_from\_32(\textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, uint32\_t ip, uint16\_t port);}
\DoxyCodeLine{84 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_from\_32h(\textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, uint32\_t ip, uint16\_t port);}
\DoxyCodeLine{85 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_from\_sockaddr\_in(\textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{const} \textcolor{keyword}{struct} sockaddr\_in *src);}
\DoxyCodeLine{86 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_from\_sockaddr\_in6(\textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{const} \textcolor{keyword}{struct} sockaddr\_in6 *src);}
\DoxyCodeLine{87 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_from\_sockaddr(\textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{const} \textcolor{keyword}{struct} sockaddr\_storage *src);}
\DoxyCodeLine{88 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_from\_osa(\textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr *src);}
\DoxyCodeLine{89 }
\DoxyCodeLine{90 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_to\_in\_addr(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{struct} in\_addr *dst);}
\DoxyCodeLine{91 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_to\_in6\_addr(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{struct} in6\_addr *dst);}
\DoxyCodeLine{92 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_to\_32(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, uint32\_t *ip);}
\DoxyCodeLine{93 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_to\_32h(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, uint32\_t *ip);}
\DoxyCodeLine{94 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_to\_sockaddr\_in(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{struct} sockaddr\_in *dst);}
\DoxyCodeLine{95 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_to\_sockaddr\_in6(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{struct} sockaddr\_in6 *dst);}
\DoxyCodeLine{96 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_to\_sockaddr(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{struct} sockaddr\_storage *dst);}
\DoxyCodeLine{97 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_to\_osa(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, \textcolor{keyword}{struct} osmo\_sockaddr *dst);}
\DoxyCodeLine{98 }
\DoxyCodeLine{99 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_from\_32n(\textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, uint32\_t ip, uint16\_t port)}
\DoxyCodeLine{100         OSMO\_DEPRECATED(\textcolor{stringliteral}{"{}osmo\_sockaddr\_str\_from\_32n() actually uses *host* byte order. Use osmo\_sockaddr\_str\_from\_32h() instead"{}});}
\DoxyCodeLine{101 \textcolor{keywordtype}{int} osmo\_sockaddr\_str\_to\_32n(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr\_str *sockaddr\_str, uint32\_t *ip)}
\DoxyCodeLine{102         OSMO\_DEPRECATED(\textcolor{stringliteral}{"{}osmo\_sockaddr\_str\_to\_32n() actually uses *host* byte order. Use osmo\_sockaddr\_str\_to\_32h() instead"{}});}
\DoxyCodeLine{103 }

\end{DoxyCode}
