summaryrefslogtreecommitdiffabout
path: root/pumpkin/StringsAttached.m
Side-by-side diff
Diffstat (limited to 'pumpkin/StringsAttached.m') (more/less context) (ignore whitespace changes)
-rw-r--r--pumpkin/StringsAttached.m19
1 files changed, 19 insertions, 0 deletions
diff --git a/pumpkin/StringsAttached.m b/pumpkin/StringsAttached.m
new file mode 100644
index 0000000..8ad5868
--- a/dev/null
+++ b/pumpkin/StringsAttached.m
@@ -0,0 +1,19 @@
+
+#import "StringsAttached.h"
+#include <arpa/inet.h>
+
+@implementation NSString (StringsAttached)
+
++ stringWithSocketAddress:(const struct sockaddr_in*)sin {
+ return [NSString stringWithFormat:@"%@:%u",[NSString stringWithHostAddress:sin],ntohs(sin->sin_port)];
+}
++ stringWithHostAddress:(const struct sockaddr_in*)sin {
+ char tmp[32];
+ addr2ascii(sin->sin_family,&sin->sin_addr,sizeof(sin->sin_addr),tmp);
+ return @(tmp);
+}
++ (id)stringWithPortNumber:(const struct sockaddr_in *)sin {
+ return [NSString stringWithFormat:@"%u",ntohs(sin->sin_port)];
+}
+
+@end