Bugs 1287, 1257

Replaces #1139 

https://redmine.openinfosecfoundation.org/issues/1287
https://redmine.openinfosecfoundation.org/issues/1257

Prscript:
- PR build: https://buildbot.openinfosecfoundation.org/builders/inliniac/builds/29
- PR pcaps: https://buildbot.openinfosecfoundation.org/builders/inliniac-pcap/builds/29