You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/12/08 06:57:09 UTC

[GitHub] [nuttx] XuNeo opened a new pull request, #7820: libc/netdb: add proto.c

XuNeo opened a new pull request, #7820:
URL: https://github.com/apache/nuttx/pull/7820

   
   ## Summary
   Add getproto related APIs.
   
   Please note code is originated from [musl-libc](https://git.musl-libc.org/cgit/musl/tree/src/network/proto.c)
   
   ## Impact
   No.
   
   ## Testing
   Self tested.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] XuNeo commented on a diff in pull request #7820: libc/netdb: add proto.c

Posted by GitBox <gi...@apache.org>.
XuNeo commented on code in PR #7820:
URL: https://github.com/apache/nuttx/pull/7820#discussion_r1043457683


##########
include/netdb.h:
##########
@@ -222,6 +222,8 @@ struct protoent
                             * alternative protocol names, terminated by a
                             * null pointer. */
   int        p_proto;      /* The protocol number. */
+  int        idx;          /* Index used by the local database, required

Review Comment:
   `uint8_t` is enough for `idx`, there is no doubt to change it.
   For `p_proto`, `int` is used in FreeBSD etc. impementation, should we keep it consistent?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] XuNeo commented on a diff in pull request #7820: libc/netdb: add proto.c

Posted by GitBox <gi...@apache.org>.
XuNeo commented on code in PR #7820:
URL: https://github.com/apache/nuttx/pull/7820#discussion_r1043458714


##########
libs/libc/netdb/lib_protor.c:
##########
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * libs/libc/netdb/lib_protor.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const unsigned char g_protos[] =
+{
+  "\000ip\0"
+  "\001icmp\0"
+  "\002igmp\0"
+  "\003ggp\0"
+  "\004ipencap\0"
+  "\005st\0"
+  "\006tcp\0"
+  "\010egp\0"
+  "\014pup\0"
+  "\021udp\0"
+  "\024hmp\0"
+  "\026xns-idp\0"
+  "\033rdp\0"
+  "\035iso-tp4\0"
+  "\044xtp\0"
+  "\045ddp\0"
+  "\046idpr-cmtp\0"
+  "\051ipv6\0"
+  "\053ipv6-route\0"
+  "\054ipv6-frag\0"
+  "\055idrp\0"
+  "\056rsvp\0"
+  "\057gre\0"
+  "\062esp\0"
+  "\063ah\0"
+  "\071skip\0"
+  "\072ipv6-icmp\0"
+  "\073ipv6-nonxt\0"
+  "\074ipv6-opts\0"
+  "\111rspf\0"
+  "\121vmtp\0"
+  "\131ospf\0"
+  "\136ipip\0"
+  "\142encap\0"
+  "\147pim\0"
+  "\377raw"
+};
+
+static const char *g_aliases;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void setprotoent_r(int stayopen, FAR struct protoent * result_buf)

Review Comment:
   Corrected.



##########
libs/libc/netdb/lib_protor.c:
##########
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * libs/libc/netdb/lib_protor.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const unsigned char g_protos[] =
+{
+  "\000ip\0"
+  "\001icmp\0"
+  "\002igmp\0"
+  "\003ggp\0"
+  "\004ipencap\0"
+  "\005st\0"
+  "\006tcp\0"
+  "\010egp\0"
+  "\014pup\0"
+  "\021udp\0"
+  "\024hmp\0"
+  "\026xns-idp\0"
+  "\033rdp\0"
+  "\035iso-tp4\0"
+  "\044xtp\0"
+  "\045ddp\0"
+  "\046idpr-cmtp\0"
+  "\051ipv6\0"
+  "\053ipv6-route\0"
+  "\054ipv6-frag\0"
+  "\055idrp\0"
+  "\056rsvp\0"
+  "\057gre\0"
+  "\062esp\0"
+  "\063ah\0"
+  "\071skip\0"
+  "\072ipv6-icmp\0"
+  "\073ipv6-nonxt\0"
+  "\074ipv6-opts\0"
+  "\111rspf\0"
+  "\121vmtp\0"
+  "\131ospf\0"
+  "\136ipip\0"
+  "\142encap\0"
+  "\147pim\0"
+  "\377raw"
+};
+
+static const char *g_aliases;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void setprotoent_r(int stayopen, FAR struct protoent * result_buf)
+{
+  result_buf->idx = 0;
+}
+
+void endprotoent_r(FAR struct protoent * result_buf)

Review Comment:
   Corrected.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 merged pull request #7820: libc/netdb: add proto.c

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #7820:
URL: https://github.com/apache/nuttx/pull/7820


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7820: libc/netdb: add proto.c

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7820:
URL: https://github.com/apache/nuttx/pull/7820#discussion_r1043056846


##########
include/netdb.h:
##########
@@ -222,6 +222,8 @@ struct protoent
                             * alternative protocol names, terminated by a
                             * null pointer. */
   int        p_proto;      /* The protocol number. */
+  int        idx;          /* Index used by the local database, required

Review Comment:
   Maybe we can make it more compact like
   ```
   uint8_t p_proto;
   uint16_t idx;
   ```
   ?



##########
libs/libc/netdb/lib_protor.c:
##########
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * libs/libc/netdb/lib_protor.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const unsigned char g_protos[] =
+{
+  "\000ip\0"
+  "\001icmp\0"
+  "\002igmp\0"
+  "\003ggp\0"
+  "\004ipencap\0"
+  "\005st\0"
+  "\006tcp\0"
+  "\010egp\0"
+  "\014pup\0"
+  "\021udp\0"
+  "\024hmp\0"
+  "\026xns-idp\0"
+  "\033rdp\0"
+  "\035iso-tp4\0"
+  "\044xtp\0"
+  "\045ddp\0"
+  "\046idpr-cmtp\0"
+  "\051ipv6\0"
+  "\053ipv6-route\0"
+  "\054ipv6-frag\0"
+  "\055idrp\0"
+  "\056rsvp\0"
+  "\057gre\0"
+  "\062esp\0"
+  "\063ah\0"
+  "\071skip\0"
+  "\072ipv6-icmp\0"
+  "\073ipv6-nonxt\0"
+  "\074ipv6-opts\0"
+  "\111rspf\0"
+  "\121vmtp\0"
+  "\131ospf\0"
+  "\136ipip\0"
+  "\142encap\0"
+  "\147pim\0"
+  "\377raw"
+};
+
+static const char *g_aliases;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void setprotoent_r(int stayopen, FAR struct protoent * result_buf)

Review Comment:
   ```suggestion
   void setprotoent_r(int stayopen, FAR struct protoent *result_buf)
   ```



##########
libs/libc/netdb/lib_protor.c:
##########
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * libs/libc/netdb/lib_protor.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const unsigned char g_protos[] =
+{
+  "\000ip\0"

Review Comment:
   I'm not sure which is better, but just an idea that maybe `\x0` (hex) format may bring more readability.



##########
libs/libc/netdb/lib_protor.c:
##########
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * libs/libc/netdb/lib_protor.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const unsigned char g_protos[] =
+{
+  "\000ip\0"
+  "\001icmp\0"
+  "\002igmp\0"
+  "\003ggp\0"
+  "\004ipencap\0"
+  "\005st\0"
+  "\006tcp\0"
+  "\010egp\0"
+  "\014pup\0"
+  "\021udp\0"
+  "\024hmp\0"
+  "\026xns-idp\0"
+  "\033rdp\0"
+  "\035iso-tp4\0"
+  "\044xtp\0"
+  "\045ddp\0"
+  "\046idpr-cmtp\0"
+  "\051ipv6\0"
+  "\053ipv6-route\0"
+  "\054ipv6-frag\0"
+  "\055idrp\0"
+  "\056rsvp\0"
+  "\057gre\0"
+  "\062esp\0"
+  "\063ah\0"
+  "\071skip\0"
+  "\072ipv6-icmp\0"
+  "\073ipv6-nonxt\0"
+  "\074ipv6-opts\0"
+  "\111rspf\0"
+  "\121vmtp\0"
+  "\131ospf\0"
+  "\136ipip\0"
+  "\142encap\0"
+  "\147pim\0"
+  "\377raw"
+};
+
+static const char *g_aliases;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void setprotoent_r(int stayopen, FAR struct protoent * result_buf)
+{
+  result_buf->idx = 0;
+}
+
+void endprotoent_r(FAR struct protoent * result_buf)

Review Comment:
   ```suggestion
   void endprotoent_r(FAR struct protoent *result_buf)
   ```



##########
libs/libc/netdb/lib_protor.c:
##########
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * libs/libc/netdb/lib_protor.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const unsigned char g_protos[] =
+{
+  "\000ip\0"
+  "\001icmp\0"
+  "\002igmp\0"
+  "\003ggp\0"
+  "\004ipencap\0"
+  "\005st\0"
+  "\006tcp\0"
+  "\010egp\0"
+  "\014pup\0"
+  "\021udp\0"
+  "\024hmp\0"
+  "\026xns-idp\0"
+  "\033rdp\0"
+  "\035iso-tp4\0"
+  "\044xtp\0"
+  "\045ddp\0"
+  "\046idpr-cmtp\0"
+  "\051ipv6\0"
+  "\053ipv6-route\0"
+  "\054ipv6-frag\0"
+  "\055idrp\0"
+  "\056rsvp\0"
+  "\057gre\0"
+  "\062esp\0"
+  "\063ah\0"
+  "\071skip\0"
+  "\072ipv6-icmp\0"
+  "\073ipv6-nonxt\0"
+  "\074ipv6-opts\0"
+  "\111rspf\0"
+  "\121vmtp\0"
+  "\131ospf\0"
+  "\136ipip\0"
+  "\142encap\0"
+  "\147pim\0"
+  "\377raw"
+};
+
+static const char *g_aliases;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void setprotoent_r(int stayopen, FAR struct protoent * result_buf)
+{
+  result_buf->idx = 0;
+}
+
+void endprotoent_r(FAR struct protoent * result_buf)
+{
+  result_buf->idx = 0;
+}
+
+int getprotoent_r(FAR struct protoent *result_buf, FAR char *buf,

Review Comment:
   so `buf` is not used for now?



##########
libs/libc/netdb/lib_protor.c:
##########
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * libs/libc/netdb/lib_protor.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const unsigned char g_protos[] =
+{
+  "\000ip\0"
+  "\001icmp\0"
+  "\002igmp\0"
+  "\003ggp\0"
+  "\004ipencap\0"
+  "\005st\0"
+  "\006tcp\0"
+  "\010egp\0"
+  "\014pup\0"
+  "\021udp\0"
+  "\024hmp\0"
+  "\026xns-idp\0"
+  "\033rdp\0"
+  "\035iso-tp4\0"
+  "\044xtp\0"
+  "\045ddp\0"
+  "\046idpr-cmtp\0"
+  "\051ipv6\0"
+  "\053ipv6-route\0"
+  "\054ipv6-frag\0"
+  "\055idrp\0"
+  "\056rsvp\0"
+  "\057gre\0"
+  "\062esp\0"
+  "\063ah\0"
+  "\071skip\0"
+  "\072ipv6-icmp\0"
+  "\073ipv6-nonxt\0"
+  "\074ipv6-opts\0"
+  "\111rspf\0"
+  "\121vmtp\0"
+  "\131ospf\0"
+  "\136ipip\0"
+  "\142encap\0"
+  "\147pim\0"
+  "\377raw"
+};
+
+static const char *g_aliases;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void setprotoent_r(int stayopen, FAR struct protoent * result_buf)
+{
+  result_buf->idx = 0;
+}
+
+void endprotoent_r(FAR struct protoent * result_buf)
+{
+  result_buf->idx = 0;
+}
+
+int getprotoent_r(FAR struct protoent *result_buf, FAR char *buf,
+                  size_t buflen, FAR struct protoent **result)
+{
+  int idx = result_buf->idx;
+  if (idx >= sizeof(g_protos))
+    {
+      return ENOENT;
+    }
+
+  result_buf->p_proto = g_protos[idx];
+  result_buf->p_name = (char *)&g_protos[idx + 1];
+  result_buf->p_aliases = (char **)&g_aliases;
+  idx += strlen(result_buf->p_name) + 2;
+  result_buf->idx = idx;
+  *result = result_buf;
+
+  return OK;

Review Comment:
   ```suggestion
     if (idx >= sizeof(g_protos))
       {
         *result = NULL;
       }
     else
       {
         result_buf->p_proto = g_protos[idx];
         result_buf->p_name = (char *)&g_protos[idx + 1];
         result_buf->p_aliases = (char **)&g_aliases;
         idx += strlen(result_buf->p_name) + 2;
         result_buf->idx = idx;
         *result = result_buf;
       }
     return *result == NULL ? ENOENT : OK;
   ```
   or just set `*result` to `NULL` before `return ENOENT;`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] XuNeo commented on a diff in pull request #7820: libc/netdb: add proto.c

Posted by GitBox <gi...@apache.org>.
XuNeo commented on code in PR #7820:
URL: https://github.com/apache/nuttx/pull/7820#discussion_r1044599835


##########
include/netdb.h:
##########
@@ -222,6 +222,8 @@ struct protoent
                             * alternative protocol names, terminated by a
                             * null pointer. */
   int        p_proto;      /* The protocol number. */
+  uint8_t    idx;          /* Index used by the local database, required

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] XuNeo commented on a diff in pull request #7820: libc/netdb: add proto.c

Posted by GitBox <gi...@apache.org>.
XuNeo commented on code in PR #7820:
URL: https://github.com/apache/nuttx/pull/7820#discussion_r1043460087


##########
libs/libc/netdb/lib_protor.c:
##########
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * libs/libc/netdb/lib_protor.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const unsigned char g_protos[] =
+{
+  "\000ip\0"

Review Comment:
   `\0` is commonly written to be string end as taught on book. `\x0` makes me think this is a special number that will be used later but not as a string end. I'm OK to both, but prefer `\0`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] XuNeo commented on a diff in pull request #7820: libc/netdb: add proto.c

Posted by GitBox <gi...@apache.org>.
XuNeo commented on code in PR #7820:
URL: https://github.com/apache/nuttx/pull/7820#discussion_r1043459206


##########
libs/libc/netdb/lib_protor.c:
##########
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * libs/libc/netdb/lib_protor.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const unsigned char g_protos[] =
+{
+  "\000ip\0"
+  "\001icmp\0"
+  "\002igmp\0"
+  "\003ggp\0"
+  "\004ipencap\0"
+  "\005st\0"
+  "\006tcp\0"
+  "\010egp\0"
+  "\014pup\0"
+  "\021udp\0"
+  "\024hmp\0"
+  "\026xns-idp\0"
+  "\033rdp\0"
+  "\035iso-tp4\0"
+  "\044xtp\0"
+  "\045ddp\0"
+  "\046idpr-cmtp\0"
+  "\051ipv6\0"
+  "\053ipv6-route\0"
+  "\054ipv6-frag\0"
+  "\055idrp\0"
+  "\056rsvp\0"
+  "\057gre\0"
+  "\062esp\0"
+  "\063ah\0"
+  "\071skip\0"
+  "\072ipv6-icmp\0"
+  "\073ipv6-nonxt\0"
+  "\074ipv6-opts\0"
+  "\111rspf\0"
+  "\121vmtp\0"
+  "\131ospf\0"
+  "\136ipip\0"
+  "\142encap\0"
+  "\147pim\0"
+  "\377raw"
+};
+
+static const char *g_aliases;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void setprotoent_r(int stayopen, FAR struct protoent * result_buf)
+{
+  result_buf->idx = 0;
+}
+
+void endprotoent_r(FAR struct protoent * result_buf)
+{
+  result_buf->idx = 0;
+}
+
+int getprotoent_r(FAR struct protoent *result_buf, FAR char *buf,
+                  size_t buflen, FAR struct protoent **result)
+{
+  int idx = result_buf->idx;
+  if (idx >= sizeof(g_protos))
+    {
+      return ENOENT;
+    }
+
+  result_buf->p_proto = g_protos[idx];
+  result_buf->p_name = (char *)&g_protos[idx + 1];
+  result_buf->p_aliases = (char **)&g_aliases;
+  idx += strlen(result_buf->p_name) + 2;
+  result_buf->idx = idx;
+  *result = result_buf;
+
+  return OK;

Review Comment:
   Corrected.



##########
libs/libc/netdb/lib_protor.c:
##########
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * libs/libc/netdb/lib_protor.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const unsigned char g_protos[] =
+{
+  "\000ip\0"
+  "\001icmp\0"
+  "\002igmp\0"
+  "\003ggp\0"
+  "\004ipencap\0"
+  "\005st\0"
+  "\006tcp\0"
+  "\010egp\0"
+  "\014pup\0"
+  "\021udp\0"
+  "\024hmp\0"
+  "\026xns-idp\0"
+  "\033rdp\0"
+  "\035iso-tp4\0"
+  "\044xtp\0"
+  "\045ddp\0"
+  "\046idpr-cmtp\0"
+  "\051ipv6\0"
+  "\053ipv6-route\0"
+  "\054ipv6-frag\0"
+  "\055idrp\0"
+  "\056rsvp\0"
+  "\057gre\0"
+  "\062esp\0"
+  "\063ah\0"
+  "\071skip\0"
+  "\072ipv6-icmp\0"
+  "\073ipv6-nonxt\0"
+  "\074ipv6-opts\0"
+  "\111rspf\0"
+  "\121vmtp\0"
+  "\131ospf\0"
+  "\136ipip\0"
+  "\142encap\0"
+  "\147pim\0"
+  "\377raw"
+};
+
+static const char *g_aliases;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void setprotoent_r(int stayopen, FAR struct protoent * result_buf)
+{
+  result_buf->idx = 0;
+}
+
+void endprotoent_r(FAR struct protoent * result_buf)
+{
+  result_buf->idx = 0;
+}
+
+int getprotoent_r(FAR struct protoent *result_buf, FAR char *buf,

Review Comment:
   Yes. `buf` is supposed to store the string field, but currently `result_buf->p_aliases = (char **)&g_aliases;`  is fixed, so leaving `buf` unused.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7820: libc/netdb: add proto.c

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7820:
URL: https://github.com/apache/nuttx/pull/7820#discussion_r1044333403


##########
libs/libc/netdb/lib_protor.c:
##########
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * libs/libc/netdb/lib_protor.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const unsigned char g_protos[] =
+{
+  "\000ip\0"

Review Comment:
   Ok. Let's keep it



##########
include/netdb.h:
##########
@@ -222,6 +222,8 @@ struct protoent
                             * alternative protocol names, terminated by a
                             * null pointer. */
   int        p_proto;      /* The protocol number. */
+  uint8_t    idx;          /* Index used by the local database, required

Review Comment:
   Let's change `p_proto` to `uint8_t` as well. I do not see that it can carry more than 8-bits



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on pull request #7820: libc/netdb: add proto.c

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on PR #7820:
URL: https://github.com/apache/nuttx/pull/7820#issuecomment-1344158412

   musl-libc is MIT licensed project. If we original some code from it than what will be the license here.
   @btashton @jerpelea do you know? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on pull request #7820: libc/netdb: add proto.c

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7820:
URL: https://github.com/apache/nuttx/pull/7820#issuecomment-1344203045

   let's add copyright to https://github.com/apache/nuttx/blob/master/LICENSE?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org