chiark / gitweb /
socket-util: introduce address_label_valid
[elogind.git] / src / basic / socket-util.c
index 9ec9012611c6346141bc276599548702042b6e0c..68773d54cc2f389f5ef3e11dc1022783898e0252 100644 (file)
@@ -904,6 +904,26 @@ bool ifname_valid(const char *p) {
         return true;
 }
 
+bool address_label_valid(const char *p) {
+
+        if (isempty(p))
+                return false;
+
+        if (strlen(p) >= IFNAMSIZ)
+                return false;
+
+        while (*p) {
+                if ((uint8_t) *p >= 127U)
+                        return false;
+
+                if ((uint8_t) *p <= 31U)
+                        return false;
+                p++;
+        }
+
+        return true;
+}
+
 int getpeercred(int fd, struct ucred *ucred) {
         socklen_t n = sizeof(struct ucred);
         struct ucred u;